home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscGaugePalette / MiscGaugeView.subproj / MiscGaugeView.m < prev    next >
Encoding:
Text File  |  1995-04-14  |  5.3 KB  |  267 lines

  1. /****************************************************************************
  2.   CLASS:                MiscGaugeView
  3.   
  4.   See the interface file for more information on this class.
  5.  
  6.   This object is included in the MiscKit by permission from the author
  7.   and its use is governed by the MiscKit license, found in the file
  8.   "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  9.   for a list of all applicable permissions and restrictions.
  10.  ****************************************************************************/
  11.  
  12. #import <appkit/appkit.h>
  13. #import "MiscGaugeCell.h"
  14. #import "MiscGaugeView.h"
  15.  
  16. // The cell our Control will display.
  17. id  myCellClass;
  18.  
  19.  
  20. @implementation MiscGaugeView 
  21.  
  22. + initialize
  23. {
  24.     if (self == [MiscGaugeView class])
  25.         // By default use the MiscGaugeCell cell.
  26.         myCellClass = [MiscGaugeCell class];
  27.     return self;
  28. }
  29.  
  30.  
  31. + setCellClass: aClass
  32. {
  33.     myCellClass = aClass;
  34.     return self;
  35. }
  36.  
  37.  
  38. - initFrame: (const NXRect *)frameRect
  39. {
  40.     // Basic initFrame method which just calls the more complicated 
  41.     // initFrame:min:max... method with some generally good default values.
  42.     [self initFrame:frameRect min:0.0 max:100.0 
  43.             startAngle:215.0 range:250.0 tickInterval:10]; 
  44.     return self;
  45. }
  46.  
  47.  
  48. - initFrame:(const NXRect *)frameRect min:(float)min max:(float)max 
  49.     startAngle:(float)start range:(float)range tickInterval:(int)interval
  50. {
  51.     if ([super initFrame: frameRect] == nil)
  52.         return nil;
  53.         
  54.     // Set ourselves to use our gaugecell. Free the old cell.
  55.      [ [self setCell: [ [myCellClass alloc] init] ] free];
  56. //    [self setOpaque: NO];
  57.         
  58.     [self setStartAngle: start];
  59.     [self setAngleRange: range];
  60.     [self setTickInterval: interval];
  61.     [self setMinValue: min];
  62.     [self setMaxValue: max];
  63.     [self setFloatValue: min];
  64.     [self setTitleFont: [Font newFont: "Helvetica" size: 10 
  65.                     matrix: NX_IDENTITYMATRIX] ];
  66.     return self;
  67. }
  68.  
  69.  
  70. - (float)maxValue { return [ (MiscGaugeCell *)[self cell] maxValue]; }
  71. - (float)minValue { return [ (MiscGaugeCell *)[self cell] minValue]; }
  72.  
  73.  
  74. - setMaxValue: (float)max 
  75.     // Don't redraw if the new max is the same as the old.
  76.     if (max != [ (MiscGaugeCell *)[self cell] maxValue])
  77.     {
  78.         [ (MiscGaugeCell *)[self cell] setMaxValue: max]; 
  79.         [self update];
  80.      }
  81.     return self; 
  82. }
  83.  
  84.  
  85. - setMinValue: (float)min 
  86.     // Don't redraw if the new min is the same as the old.
  87.     if (min != [ (MiscGaugeCell *)[self cell] maxValue])
  88.     {
  89.         [ (MiscGaugeCell *)[self cell] setMinValue: min]; 
  90.         [self update];
  91.      }
  92.     return self; 
  93. }
  94.  
  95.  
  96. - (float)startAngle { return [ [self cell] startAngle]; }
  97. - (float)angleRange { return [ [self cell] angleRange]; }
  98. - (int)tickInterval { return [ [self cell] tickInterval]; }
  99. - (float)tickRatio { return [ [self cell] tickRatio]; }
  100. - (float)handRatio { return [ [self cell] handRatio]; }
  101.  
  102.  
  103. - setStartAngle:(float)newValue
  104. {
  105.     if (newValue != [ [self cell] startAngle])
  106.     {
  107.         [ [self cell] setStartAngle: newValue];
  108.         [self update];
  109.      }
  110.     return self;
  111. }
  112.  
  113.  
  114. - setAngleRange:(float)newValue
  115. {
  116.     if (newValue != [ [self cell] angleRange])
  117.     {
  118.         [ [self cell] setAngleRange: newValue];
  119.         [self update];
  120.      }
  121.     return self;
  122. }
  123.  
  124.  
  125. - setTickInterval:(int)newValue
  126. {
  127.     if (newValue != [ [self cell] tickInterval])
  128.     {
  129.         [ [self cell] setTickInterval: newValue];
  130.         [self update];
  131.      }
  132.     return self;
  133. }
  134.  
  135.  
  136. - setTickRatio: (float)newRatio
  137. {
  138.     if (newRatio != [ [self cell] tickRatio])
  139.     {
  140.         [ [self cell] setTickRatio: newRatio];
  141.         [self update];
  142.      }
  143.     return self;
  144. }
  145.  
  146.  
  147. - setHandRatio: (float)newRatio
  148. {
  149.     [ [self cell] setHandRatio: newRatio];
  150.     [self updateCellInside: [self cell] ];
  151.     return self;
  152. }
  153.  
  154.  
  155. //- (NXColor)backgroundColor { return [ [self cell] backgroundColor]; }
  156. - (NXColor)gaugeColor { return [ [self cell] gaugeColor]; }
  157. - (NXColor)textColor { return [ [self cell] textColor]; }
  158.  
  159. /*
  160. - setBackgroundColor: (NXColor)color
  161. {
  162.     if (NXEqualColor (color, [self backgroundColor]) == NO)
  163.     {
  164.         [ [self cell] setBackgroundColor: color];
  165.         [self update];
  166.      }
  167.     return self;
  168. }
  169. */
  170.  
  171. - setGaugeColor: (NXColor)color
  172. {
  173.     if (NXEqualColor (color, [self gaugeColor]) == NO)
  174.     {
  175.         [ [self cell] setGaugeColor: color];
  176.         [self update];
  177.      }
  178.     return self;
  179. }
  180.  
  181.  
  182. - setTextColor: (NXColor)color
  183. {
  184.     if (NXEqualColor (color, [self textColor]) == NO)
  185.     {
  186.         [ [self cell] setTextColor: color];
  187.         [self update];
  188.      }
  189.     return self;
  190. }
  191.  
  192.  
  193. //- (float)backgroundGray    { return [ [self cell] backgroundGray]; }
  194. - (float)gaugeGray { return [ [self cell] gaugeGray]; }
  195. - (float)textGray { return [ [self cell] textGray]; }
  196.  
  197. /*
  198. - setBackgroundGray: (float)gray
  199. {
  200.     if (gray != [self backgroundGray])
  201.     {
  202.         [ [self cell] setBackgroundGray: gray];
  203.         [self update];
  204.      }
  205.     return self;
  206. }
  207. */
  208.  
  209. - setGaugeGray: (float)gray
  210. {
  211.     if (gray != [self gaugeGray])
  212.     {
  213.         [ [self cell] setGaugeGray: gray];
  214.         [self update];
  215.      }
  216.     return self;
  217. }
  218.  
  219.  
  220. - setTextGray: (float)gray
  221. {
  222.     if (gray != [self textGray])
  223.     {
  224.         [ [self cell] setTextGray: gray];
  225.         [self update];
  226.      }
  227.     return self;
  228. }
  229.  
  230.  
  231. - titleFont { return [ [self cell] titleFont]; }
  232. - (const char *)title { return [ [self cell] title]; }
  233. - (int)titlePosition { return [ [self cell] titlePosition]; }
  234.  
  235.  
  236. - setTitleFont: newFont
  237. {
  238.     [ [self cell] setTitleFont: newFont];
  239.     [self update];
  240.     return self;
  241. }
  242.  
  243.  
  244. - setTitle: (const char *)newTitle
  245. {
  246.     [ [self cell] setTitle: newTitle];
  247.     [self update];
  248.     return self;
  249. }
  250.  
  251.  
  252. - setTitlePosition: (int)newPos
  253. {
  254.     // Valid positions are NX_ATTOP and NX_ATBOTTOM.
  255.     if (newPos != [self titlePosition])
  256.     {
  257.         [ [self cell] setTitlePosition: newPos];
  258.         [self update];
  259.      }
  260.     return self;
  261. }
  262.  
  263. @end
  264.  
  265.